<template>
  <div @resize="handleResize">
    <el-row :gutter="24">
      <el-col san="24" class="ivu-mb">
        <div class="box">
          <el-card :bordered="false" dis-hover class="dashboard-console-visit">
            <div
              style="
                width: 100%;
                height: 100%;
                background: linear-gradient(162deg, #ecf4fe, #fff 20%);
                padding: 16px;
                border-radius: 8px;
              "
            >
              <div slot="title">
                <el-row type="flex" justify="center" align="middle">
                  <el-col :span="8">
                    <div class="header">
                      <img src="~@/assets/images/home/ordernum-text.png" alt />
                      <span data-time="2023-05-04 12:58:53" class="up-datetime">更新于{{ now }}</span>
                    </div>
                  </el-col>
                  <el-col :span="16" class="ivu-text-right">
                    <div class="rank-type">
                      <button
                        :class="visitDate == 'month' ? 'select-btn' : ''"
                        @click="rankTypeChange('month')"
                      >本月</button>
                      <button
                        :class="visitDate == 'thirtyday' ? 'select-btn' : ''"
                        @click="rankTypeChange('thirtyday')"
                      >近一月</button>
                      <button
                        :class="visitDate == 'half_year' ? 'select-btn' : ''"
                        @click="rankTypeChange('half_year')"
                      >近半年</button>
                      <button
                        :class="visitDate == 'year' ? 'select-btn' : ''"
                        @click="rankTypeChange('year')"
                      >全年</button>
                    </div>
                  </el-col>
                </el-row>
              </div>
              <echarts-from
                ref="visitChart"
                :series="series"
                :infoList="infoList"
                v-if="infoList"
                :yAxisData="yAxisData"
              ></echarts-from>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
  <script>
// import { serviceOrderApi } from '@/api/index';
import { orderChartApi } from '@/api/home.js';
import echartsFrom from '@/components/echarts/index';
export default {
  props: {
    now: {
      default: '',
    },
  },
  components: { echartsFrom },
  data() {
    return {
      infoList: null,
      visitDate: 'month',
      series: [],
      yAxisData: [],
    };
  },
  methods: {
    // 统计
    getServiceStatistic() {
      let data = {
        cycle: this.visitDate,
      };
      
      orderChartApi(data)
        .then(async (res) => {
          this.infoList = res || {};
          (this.series = this.infoList.series || []),
            (this.yAxisData = [
              {
                type: 'value',
                name: '金额',
                axisLine: {
                  show: false,
                },
                axisTick: {
                  show: false,
                },
                axisLabel: {
                  textStyle: {
                    color: '#7F8B9C',
                  },
                },
                splitLine: {
                  show: true,
                  lineStyle: {
                    color: '#F5F7F9',
                  },
                },
              },
              {
                type: 'value',
                name: '订单数',
                axisLine: {
                  show: false,
                },
                axisTick: {
                  show: false,
                },
                axisLabel: {
                  textStyle: {
                    color: '#7F8B9C',
                  },
                },
                splitLine: {
                  show: true,
                  lineStyle: {
                    color: '#F5F7F9',
                  },
                },
                // axisLabel: {
                //     formatter: '{value} °C'
                // }
              },
            ]);
            console.log(this.series)
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    // 时间改变
    rankTypeChange(val) {
      this.visitDate = val;
      this.series = [];
      this.yAxisData = [];
      this.getServiceStatistic();

    },

    // 监听页面宽度变化，刷新表格
    handleResize() {
      if (this.infoList) this.$refs.visitChart.handleResize();
    },
  },
  created() {
    this.getServiceStatistic();
  },
};
</script>
<style scoped  lang="stylus">
.box >>> .ivu-card {
  border-radius: 18px;
  padding: 2px;
}

.box >>>.ivu-card-body {
  padding: 0 !important;
}

.box >>>.ivu-card-head {
  border-bottom: none !important;
}

.box >>> .ivu-radio-group-button {
  display: inline-flex;
  column-gap: 6px;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper {
  border-radius: 4px;
  border: 1px solid #dcdee2;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper-checked {
  border-radius: 4px;
  border: 1px solid;
  border-color: #2d8cf0;
  background: transparent;
  box-shadow: none;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper-checked:first-child {
  border-radius: 4px;
  border: 1px solid;
  border-color: #2d8cf0;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper:first-child {
  border-radius: 4px;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper:hover {
  border: 1px solid;
  border-color: #2d8cf0;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper:before, .ivu-radio-group-button .ivu-radio-wrapper:after {
  background: transparent;
}

.box >>> .ivu-radio-group-button .ivu-radio-wrapper:last-child {
  border-radius: 4px;
}
</style>
  <style lang="scss" scoped>
.service-rank .rank-header .rank-type .select-btn {
  border: 1px solid #428bf4;
  color: #428bf4;
}
.dashboard-console-visit {
  ul {
    li {
      list-style-type: none;
      margin-top: 12px;
    }
  }
}
.ivu-text-right {
  text-align: right;
}
.ivu-pl-8 {
  padding-left: 8px !important;
}
.header {
  display: flex;
  align-items: flex-end;
  img {
    height: 16px;
    object-fit: contain;
  }
  .up-datetime {
    font-size: 12px;
    color: #999;
    padding-left: 4px;
    transform: translateY(4px);
  }
}
.rank-type {
  display: flex;
  gap: 6px;
  flex-direction: row-reverse;
  flex-wrap: wrap;
  flex-shrink: 0;
  button {
    background: #fff;
    border: 1px solid #dcdcdc;
    color: #999;
    font-size: 10px;
    border-radius: 4px;
    cursor: pointer;
    height: 18px;
    font-size: 10px;
    line-height: 18px;
    padding: 0;
    min-width: 60px;
    text-align: center;
  }
  button:hover {
    border: 1px solid #428bf4;
    color: #428bf4;
  }
  .select-btn {
    border: 1px solid #428bf4;
    color: #428bf4;
  }
}
</style>
